<template>
	<view>
		<uni-nav-bar left-icon="back" left-text="返回" fixed="true" statusBar="true"  @clickLeft="leftAction"  title="测试基站"
			></uni-nav-bar>
		<view class="content">
			<form @submit="formSubmit">
				<view class="uni-form-item uni-row">
					<view class="title">测试配置通道</view>
					<uni-data-picker class="uni-picker" v-model="channel" :localdata="item" popup-title="测试配置通道"
						@change="onchange" @nodeclick="onnodeclick"></uni-data-picker>
				</view>
				<view class="uni-form-item uni-row">
					<view class="title">测试模式</view>
					<input class="uni-input" name="HT" v-model="value" placeholder="测试模式" />
				</view>
				<view class="uni-btn-v">
					<button form-type="submit">测试基站</button>
				</view>
			</form>
			<textarea class="text-area" v-model="result"></textarea>
			
		</view>	
	</view>
</template>

<script>
	import uniNavBar from '@/uni_modules/uni-nav-bar/components/uni-nav-bar/uni-nav-bar.vue'
	import Vue from 'vue'
	import wsconnect from '@/api/webservice.js'
	export default {
		data() {
			return {
				item:[
					{text:'CG',value:'CG'},
					{text:'D1',value:'D1'},
					{text:'D2',value:'D2'},
					{text:'AM',value:'AM'},
				],
				channel:'CG',
				value:'CW',
				result:'',
			};
		},
		
		onLoad(options) {
			this.bs_id = options.id
			console.log(this.bs_id)
			this.$http.get('/netty/station/' + this.bs_id).then(res => {
				const form = res.data.data
				this.form = form
			}).catch(err => {
				uni.showModal({
					content: '出错了，请稍后再试',
					showCancel: false
				})
			})
			uni.hideLoading()
		},
		components: {
			uniNavBar
		},
		methods: {
			leftAction() {
				uni.navigateBack({
					delta: 1
				});
			},
			onchange(e) {
				this.channel = e.detail.value[0].value
			},
			onnodeclick(node) {
				console.log(node)
			},
			formSubmit: function(e) {
				const sendCmdTagName = this.form.sendCmdTagName
				const reqTagName = this.form.reqTagName
				wsconnect.requestJson({
					items: [sendCmdTagName + '.DESC'],
					vals: ['BsTestRq,/'+this.channel+'='+this.value+'/'],
					type: "SetDataByName",
				}, reqTagName).then(res => {
					this.result =  this.channel +'='+this.value +'   ' +this.$moment().format("yyyy-MM-DD HH:mm:ss") +'：'+ res +'\r\n'  + this.result 
					wsconnect.clearReqData(1, reqTagName)
				}).catch(error => {
					if (error.code == 1) {
						uni.redirectTo({
							url: "../index/index"
						})
					} else {
						uni.showModal({
							content: error.msg,
							showCancel: false
						})
					}
				})
				
			}
		}
	}
</script>

<style lang="scss">

	@import '@/common/uni.css';
	@import '@/common/uni-nvue.scss';

	.uni-form-item .title {
		margin-left: 20rpx;
		padding: 20rpx 0;
		width: 370rpx;
		font-size: 30rpx;
	}
	
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	
	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}
	
	.uni-btn-v {
		margin-left: 50rpx;
		margin-right: 50rpx;
		height: 40rpx;
	}
	
	.text-area {
		justify-content: center;
		width: 100%;
		margin-top: 80rpx;
		height: 600rpx;
	}
	
	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
	
	.uni-input {
		background-color: #F1F1F1;
		height: 60rpx;
		border: 1px solid #DDD;
		margin-right: 50rpx;
	}

	.uni-picker {
		background-color: #F1F1F1;
		height: 60rpx;
		margin-right: 50rpx;
	}
</style>
